package cc.vv.baselibrary.view.columnchart

import android.content.Context
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import cc.vv.baselibrary.R
import cc.vv.baselibrary.util.BaseTimeUtil
import cc.vv.baselibrary.util.LKCommonUtil
import cc.vv.baselibrary.view.BCNoScrollHorizontalRecyclerView
import cc.vv.baselibrary.view.columnchart.adapter.SingleViewHorizontalViewAdapter
import cc.vv.baselibrary.view.columnchart.bean.ShowPopwinDataObj

/**
 *
 * Created by sun.li on 2018/8/4.
 * @author sun.li
 */
class SingleViewHorizontal : LinearLayout {

    var mContext: Context? = null

    var rv_svhv_recycler_view: BCNoScrollHorizontalRecyclerView? = null

    constructor(context: Context) : super(context) {
        this.mContext = context
        initView()
        initViewEvent()
    }

    constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
        this.mContext = context
        initView()
        initViewEvent()
    }

    constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
        this.mContext = context
        initView()
        initViewEvent()
    }

    fun initView() {
        if (mContext == null) {
            return
        }
        val view = LayoutInflater.from(mContext).inflate(R.layout.view_single_view_horizontal, null)
        rv_svhv_recycler_view = view.findViewById(R.id.rv_svhv_recycler_view)
        this.addView(view)
    }

    fun initViewEvent() {
        val data = ArrayList<ShowPopwinDataObj>()
        for (i in 30..85) {
            val obj = ShowPopwinDataObj()
            obj.valueData = i.toDouble()
            obj.timeStr = BaseTimeUtil.getNowDateString(BaseTimeUtil.DATE_FORMAT_1)
            data.add(0,obj)
        }
        val adapter = SingleViewHorizontalViewAdapter(R.layout.day_graph_item_layout, data)
        rv_svhv_recycler_view?.adapter = adapter
        rv_svhv_recycler_view?.post(Runnable {
            rv_svhv_recycler_view?.scrollToPosition(data.size-1)
        })
    }
}